﻿/**
 * @author colin
 */

function declareVar(){
	filePath	= fl.configURI+ "Commands/"
	swfPanelPath= fl.configURI+"WindowSWF/";
	xmluiPath	= filePath+"setSymbolClassAsset/setSymbolClass.xml";
	currentDoc	= fl.getDocumentDOM();

	library = currentDoc.library;	
	items = library.getSelectedItems();
	selectedElements = currentDoc.selection;
	fl.outputPanel.clear();
}

function isDocOpen(){
	return (fl.getDocumentDOM()==null)?false:true;
}

function getVersion(){
	if(isDocOpen()==false){return;}
	return fl.getDocumentDOM().asVersion;
}

function getClass(){//return string
	if(isDocOpen()==false){
		return "MSG: document is not fla";
	}

	declareVar();
	if(selectedElements.length==1){
		if(selectedElements[0].instanceType=='symbol'){
			if(selectedElements[0].libraryItem.itemType == 'movie clip'){
				if(currentDoc.asVersion==3){
					if(selectedElements[0].libraryItem.linkageBaseClass=="" &&selectedElements[0].libraryItem.linkageClassName!=""){
						return "MSG: Maybe AS2 class: "+selectedElements[0].libraryItem.linkageClassName
					}
					return selectedElements[0].libraryItem.linkageBaseClass;
				}
				return selectedElements[0].libraryItem.linkageClassName;
			}else{
				return('MSG: selected item is not movieclip symbol');
			};
		}else{
			return('MSG: selected item is not symbol');
		}
	}else{
		return 'MSG: Please select 1 item on Stage';
	}
}

function setClass(className){
	if(isDocOpen()==false){
		alert("MSG: document is not fla");
		return;
	}
	if(className==""){
		alert("class name is null");
		return;
	}

	declareVar();
	if(selectedElements.length==1){
		if(selectedElements[0].instanceType=='symbol'){
			if(selectedElements[0].libraryItem.itemType == 'movie clip'){
				var symbolItem = selectedElements[0].libraryItem;
				symbolItem.linkageExportForAS = true;
				symbolItem.linkageExportInFirstFrame = true;
				symbolItem.linkageIdentifier = String(symbolItem.name).split('/').pop();

				if(currentDoc.asVersion==3){
					symbolItem.linkageBaseClass = className;
					symbolItem.linkageClassName = symbolItem.linkageIdentifier;
					return;
				}
				symbolItem.linkageClassName = className;
			}else{
				alert('selected item is not movieclip symbol');
			};
		}else{
			alert('selected item is not symbol');
		}
	}else{
		alert('Please select 1 item on Stage');
	}
}